import { axios } from '@/utils/request'

/**
 * 查询租户列表
 * @param query
 * @returns {AxiosPromise}
 */
export function pageTenant(query){
  return axios({
    url: '/system/tenant/page',
    method: 'get',
    params: query
  });
}

/**
 * 查询租户详细
 * @param id
 * @returns {AxiosPromise}
 */
export function getTenant(id){
  return axios({
    url: '/system/tenant/' + id,
    method: 'get'
  });
}

/**
 * 新增租户
 * @param data
 * @returns {*}
 */
export function addTenant(data) {
  return axios({
    url: '/system/tenant',
    method: 'post',
    headers: {
      isEncrypt: true,
      repeatSubmit: false
    },
    data: data
  });
}

/**
 * 修改租户
 * @param data
 * @returns {AxiosPromise}
 */
export function updateTenant(data) {
  return axios({
    url: '/system/tenant',
    method: 'put',
    data: data
  });
}

/**
 * 租户状态修改
 * @param id
 * @param tenantId
 * @param status
 * @returns {*}
 */
export function changeTenantStatus(id, tenantId, status) {
  const data = {
    id,
    tenantId,
    status
  };
  return axios({
    url: '/system/tenant/changeStatus',
    method: 'put',
    data: data
  });
}

/**
 * 删除租户
 * @param id
 * @returns {AxiosPromise}
 */
export function delTenant(id) {
  return axios({
    url: '/system/tenant/' + id,
    method: 'delete'
  });
}

/**
 * 动态切换租户
 * @param tenantId
 * @returns {*}
 */
export function dynamicTenant(tenantId) {
  return axios({
    url: '/system/tenant/dynamic/' + tenantId,
    method: 'get'
  });
}

/**
 * 清除动态租户
 * @returns {*}
 */
export function dynamicClear() {
  return axios({
    url: '/system/tenant/dynamic/clear',
    method: 'get'
  });
}

/**
 * 同步租户套餐
 * @param tenantId
 * @param packageId
 * @returns {*}
 */
export function syncTenantPackage(tenantId, packageId) {
  const data = {
    tenantId,
    packageId
  };
  return axios({
    url: '/system/tenant/syncTenantPackage',
    method: 'get',
    params: data
  });
}

